package com.smomo.blog.exception;

import com.smomo.blog.common.ResultCode;
import lombok.Data;

import static com.smomo.blog.common.ResultCode.ERROR;
import static com.smomo.blog.common.ResultCode.ERROR_DEFAULT;

@Data
public class BusinessException extends RuntimeException{


    /** 异常代码 */
    private Integer code;
    /** 异常消息 */
    private String message;

    public BusinessException() {
        super();
    }

    public BusinessException(ResultCode resultCode) {
        super(resultCode.getDesc());
        this.code=resultCode.getCode();
        this.message=resultCode.getDesc();
    }

    public BusinessException(String msg) {
        super(msg);
        this.code = ERROR_DEFAULT.getCode();
        this.message = msg;
    }
    public BusinessException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.message = msg;
    }
    public BusinessException(Integer code, String msg, Throwable cause) {
        super(msg, cause);
        this.code = code;
        this.message = msg;
    }


    public BusinessException(Throwable cause) {
        super(cause);
        this.code = ERROR.getCode();
        this.message = cause.getMessage();
    }
}
